/*
 * Exploder
 * 
 * Tero Pyylampi (218437), Jussi Tuurinkoski (211594)
 *
 * Level Editor layer
 */

#ifndef EDITORLAYER_H
#define EDITORLAYER_H

#include "cocos2d.h"
#include "Box2D/Box2D.h"

class MainEngine;
class EditorScene;
class GameTouchHandle;
class GameAbstractEngine;
class GamePhysicObjectEngine;
class GameConstructionElement;

class EditorLayer : public cocos2d::CCLayer
{
public:
	// default constructor
	EditorLayer( EditorScene *scene );
	// default destructor
	~EditorLayer();

	// initialize this scene
	void initializeLayer();
	// start building a new level
	void initializeNewLevel();

	// update -function
	virtual void update( cocos2d::ccTime dt );
	
	// called when the user puts the finger on the screen
	virtual void ccTouchesBegan( cocos2d::CCSet *touches, cocos2d::CCEvent *event );
	// called when the finger moves on the screen
	virtual void ccTouchesMoved( cocos2d::CCSet *touches, cocos2d::CCEvent *event );
	// called when the user lifts the finger from the screen
	virtual void ccTouchesEnded( cocos2d::CCSet *touches, cocos2d::CCEvent *event );

	// get master
	EditorScene *getEditorScene();
	// get physics engine
	b2World *getPhysicsEngine();
	// get & set world dimensions
	b2Vec2 *getWorldDimensions();
	void setWorldDimensions( float width, float height );
	// get physic object engine
	GamePhysicObjectEngine *getPhysicObjectEngine();
	// reset currently active object
	void resetCurrentlyActiveObject();

private:
	// pointer to the main engine
	EditorScene *mEditorScene;

	// touch handler for input
	GameTouchHandle *mTouchHandle;
	// currently active element
	GameConstructionElement *mActiveElement;

	// physics engine
	b2World *mPhysicsWorld;
	// world dimensions
	b2Vec2 mWorldDimensions;

	// different engines
	std::vector< GameAbstractEngine* > *mEngines;

	// check for interface physic object button presses
	b2Body *checkForInterfacePhysicObjectButtonPresses( cocos2d::CCPoint &screenCoords, b2Vec2 &worldCoords );
	// check for existing bodies
	GameConstructionElement *checkForExistingElements( b2Vec2 &worldCoords );
};

#endif